import {
  UserPageParam,
  DeptListItem,
  MenuParams,
  RoleParams,
  RolePageParams,
  PluginParams,
  PluginPageParams,
  MenuListGetResultModel,
  DeptListGetResultModel,
  UserListGetResultModel,
  RolePageListGetResultModel,
  PluginPageListGetResultModel,
  RoleListGetResultModel,
  MenuAddParam,
  MenuUpdatedParam,
  RoleAddParam,
  RoleUpdatedParam,
  UserUpdatedParam,
  UserAddParam
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  userList = '/api/user',
  IsUserExist = '/api/user',
  DeptList = '/system/getDeptList',
  setRoleStatus = '/api/role',
  MenuList = '/api/menu',
  RolePageList = '/api/role',
  PluginPageList = '/system/getPluginListByPage',
  GetAllRoleList = '/api/role/list',
}

export const getUserList = (params: UserPageParam) =>
  defHttp.get<UserListGetResultModel>({ url: Api.userList, params }, { isPage: true });

export const addUser = (params?: UserAddParam) => defHttp.post({ url: Api.userList, params });
export const editUser = (params?: UserUpdatedParam & UserAddParam) =>
  defHttp.put({ url: Api.userList, params });

export const deleteUser = (userId: String) =>
  defHttp.delete({
    url: Api.userList + '/' + userId,
  });
export const setUserStatus = (id: number, status: number) =>
  defHttp.put({ url: Api.userList + '/' + id + '/' + status });

export const isUserExist = (username: string) =>
  defHttp.get({ url: Api.IsUserExist + '/' + username }, { errorMessageMode: 'none' });
export const getDeptList = (params?: DeptListItem) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });

export const getPluginListByPage = (params?: RolePageParams) =>
  defHttp.get<PluginPageListGetResultModel>({ url: Api.PluginPageList, params });

export const getMenuList = (params?: MenuParams) =>
  defHttp.get<MenuListGetResultModel>({ url: Api.MenuList, params });

export const addMenu = (params?: MenuAddParam) => defHttp.post({ url: Api.MenuList, params });

export const editMenu = (params?: MenuUpdatedParam & MenuAddParam) =>
  defHttp.put({ url: Api.MenuList, params });

export const deleteMenu = (menuId: Number) =>
  defHttp.delete({
    url: Api.MenuList + '/' + menuId,
  });

export const getRoleListByPage = (params?: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });

export const getAllRoleList = (params?: RoleParams) =>
  defHttp.get<RoleListGetResultModel>({ url: Api.GetAllRoleList, params });

export const addRole = (params?: RoleAddParam) => defHttp.post({ url: Api.RolePageList, params });

export const editRole = (params?: RoleUpdatedParam & RoleAddParam) =>
  defHttp.put({ url: Api.RolePageList, params });

export const deleteRole = (roleId: String) =>
  defHttp.delete({
    url: Api.RolePageList + '/' + roleId,
  });

export const setRoleStatus = (id: number, status: number) =>
  defHttp.put({ url: Api.setRoleStatus + '/' + id + '/' + status });
